package com.yyfax.ph.home.todolist;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.yyfax.common.adapter.BaseRecycleAdapter;
import com.yyfax.common.recyclerview.IViewHolder;
import com.yyfax.common.recyclerview.OnItemClickListener;
import com.yyfax.ph.R;
import com.yyfax.ph.progress.search.ProgressModel;

/**
 * 待办列表Adapter
 * Created by ying_he on 2017/11/4.<br>
 * Copyright  2017 www.yylending.com. All Rights Reserved.<br><br>
 */

public class ToDoListAdapter extends BaseRecycleAdapter<ProgressModel.ProgressBean> {

	public ToDoListAdapter() {
	}

	@Override
	public IViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
		View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_item_todo_list, null);
		return new ViewHolder(view);
	}

	@Override
	public void onBindViewHolder(IViewHolder holder, int position) {
		ViewHolder viewHolder = (ViewHolder) holder;
		final ProgressModel.ProgressBean progressBean = getDataSet().get(position);
		viewHolder.BindView(position, progressBean, mListener);
	}

	@Override
	public int getItemCount() {
		return getCount();
	}

	public static class ViewHolder extends IViewHolder {

		@BindView(R.id.name_tv)
		TextView mNameTv;
		@BindView(R.id.date_tv)
		TextView mDateTv;
		@BindView(R.id.status_tv)
		TextView mStatusTv;
		View mItemView;

		public ViewHolder(View itemView) {
			super(itemView);
			ButterKnife.bind(this, itemView);
			mItemView = itemView;
		}

		public void BindView(final int position, final ProgressModel.ProgressBean progressBean, final OnItemClickListener toDoItemClickListener) {
			mItemView.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					toDoItemClickListener.onItemClick(position, progressBean, mItemView);
				}
			});

			onBind(progressBean);
		}

		private void onBind(final ProgressModel.ProgressBean progressBean){
			mNameTv.setText(progressBean.rcmdName);
			mDateTv.setText(progressBean.referDate.substring(5, progressBean.referDate.length())); // 日期，格式：yyyy/mm/dd
			mStatusTv.setText(progressBean.status);
		}
	}
}
